package com.chinasoft.dish.mapper;

import com.chinasoft.dish.domain.Dish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface DishMapper {

    /**
     * 查询所有菜单
     * @return
     */
    @Select("select * from dish where status = 1")
    List<Dish> findAll(Dish dish);

    /**
     * 工具id查询菜单
     * @return
     */
    @Select("select * from dish where bid = #{bid}")
    List<Dish> findOne(String bid);

    /**
     * 添加菜品
     * @param dish
     */
    @Insert("insert into dish(bid,name,price,flavor,des,sales,dish_image) values(#{bid},#{name},#{price},#{flavor},#{des},#{sales},#{dishImage})")
    void addDish(Dish dish);

    /**
     * 根据商家id和菜品名删除菜品
     * @param dish
     */
    @Delete("<script> delete from dish " +
            "<where>" +
            "<if test='name !=null'>and bid = #{bid} and name like concat('%',#{name},'%')</if>" +
            "</where>" +
            "</script>")
    void delDish(Dish dish);

    /**
     * 修改菜品信息
     * @param dish
     */
    @Update("update dish set bid=#{bid},name=#{name},price=#{price},flavor=#{flavor},des=#{des},sales=#{sales},dish_image=#{dishImage} where id=#{id}")
    void updateDish(Dish dish);
}
